﻿function log(name, obj, prespace)  {
    if (!prespace) prespace = '';
    name && console.log(`${prespace}=== ${name} ===`);

    if (obj === null || obj === undefined) {
        console.log(`${prespace}${obj}`)
        return
    }

    var t = typeof (obj);
    switch (t) {
        case 'boolean':
        case 'number':
        case 'string':
            console.log(`${prespace}${obj}`);
            break;
        default:
            if (Array.isArray(obj)) {
                obj.forEach((item, idx) => {
                    log(null, `${idx}:${item}`, '    ');
                })
            } else {
                Object.keys(obj).forEach(k => {
                    log(null, `${k}:${obj[k]}`, '    ');
                })
            }
            break;
    }
}

module.exports = {
    fullurl(req) {
        return req.protocol + '://' + req.get('host') + req.originalUrl
    },
    prt(name, obj, prespace) { log(name, obj, prespace)}
}
